﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.OracleClient;
using Xiaov.SmartWeb.Application.SupCan;

namespace Xiaov.SmartWeb.Application.HXZB
{
    public partial class NhzbIndexData : System.Web.UI.Page
    {
        protected string nf = DateTime.Now.Year.ToString();
        protected string yf = (DateTime.Now.Month - 1).ToString();
        protected string dwbm = "HB"; 

        protected void Page_Load(object sender, EventArgs e)
        {
            nf = Request.QueryString["nf"];
            yf = Request.QueryString["yf"];
            dwbm = Request.QueryString["dwbm"];

            InitTable();
        }

        protected void InitTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("zbmc");
            dt.Columns.Add("bysj");
            dt.Columns.Add("bnlj");
            dt.Columns.Add("qntqlj");
            dt.Columns.Add("zbbm");
            InitLable(dt, "电   力", "NH6101");
            InitLable(dt, "原   油", "NH6102");
            InitLable(dt, "天 然 气", "NH6104");
            InitLable(dt, "汽   油", "NH6105");
            InitLable(dt, "柴   油", "NH6106");
            InitLable(dt, "能源合计", "NH6111");
            InitLable(dt, "综 合 能 耗", "NH6112");            

            #region 转换成XML
            string dataString = ConfigurationManager.AppSettings["NhzbIndex_Column"];
            ConvertToXml.Convert(dt, dataString, 0, dt.Rows.Count);           
            #endregion
        }

        protected void InitLable(DataTable dt, string sZBMC, string sZBBM)
        {
            string sbSql = "";
            sbSql = @"select round(t.xHhj-nvl(s.xHhj,0)) bysj,round(t.XHHJ) bnlj,round(r.XHHJ) qntqlj,t.zbbm from NH61 t,
                (select * from NH61 where zbbm='" + sZBBM + @"'and nf={1} and yf={0}-1 and dwbm={2}) s,
                (select * from NH61 where zbbm='" + sZBBM + @"'and nf={1}-1 and yf={0} and dwbm={2}) r 
                WHERE t.zbbm='" + sZBBM + @"' and t.nf={1} and t.yf={0} and t.dwbm={2} and t.zbbm=s.zbbm(+) and t.zbbm=r.zbbm(+)";
            OracleDataReader dr = (OracleDataReader)Maticsoft.DBUtility.DbHelperOra.ExecuteReader(string.Format(sbSql, yf, nf, "'HB'"));
            if (dr.Read())
            {
                DataRow drow = dt.NewRow();
                drow[0] = sZBMC;
                drow[1] = dr["bysj"].ToString();
                drow[2] = dr["bnlj"].ToString();
                drow[3] = dr["qntqlj"].ToString();
                drow[4] = dr["zbbm"].ToString();
                dt.Rows.Add(drow);
            }
            dr.Close();
        }
    }
}